package com.ruoyi.wcf.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wcf.domain.WcfMobileModel;
import com.ruoyi.wcf.service.IWcfMobileModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手机型号Controller
 *
 * @author WZP
 * @date 2022-04-02
 */
@RestController
@RequestMapping("/wcf/WcfMobileModel")
public class WcfMobileModelController extends BaseController
{
    @Autowired
    private IWcfMobileModelService wcfMobileModelService;

    /**
     * 查询手机型号列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(WcfMobileModel wcfMobileModel)
    {
        startPage();
        List<WcfMobileModel> list = wcfMobileModelService.selectWcfMobileModelList(wcfMobileModel);
        return getDataTable(list);
    }

    /**
     * 导出手机型号列表
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:export')")
    @Log(title = "手机型号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WcfMobileModel wcfMobileModel)
    {
        List<WcfMobileModel> list = wcfMobileModelService.selectWcfMobileModelList(wcfMobileModel);
        ExcelUtil<WcfMobileModel> util = new ExcelUtil<WcfMobileModel>(WcfMobileModel.class);
        return util.exportExcel(list, "手机型号数据");
    }

    /**
     * 获取手机型号详细信息
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return AjaxResult.success(wcfMobileModelService.selectWcfMobileModelByModelId(modelId));
    }

    /**
     * 新增手机型号
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:add')")
    @Log(title = "手机型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WcfMobileModel wcfMobileModel)
    {
        return toAjax(wcfMobileModelService.insertWcfMobileModel(wcfMobileModel));
    }

    /**
     * 修改手机型号
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:edit')")
    @Log(title = "手机型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WcfMobileModel wcfMobileModel)
    {
        return toAjax(wcfMobileModelService.updateWcfMobileModel(wcfMobileModel));
    }

    /**
     * 删除手机型号
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:remove')")
    @Log(title = "手机型号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(wcfMobileModelService.deleteWcfMobileModelByModelIds(modelIds));
    }

    /**
     * 新增手机型号
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:add')")
    @Log(title = "手机型号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Map<String,Object> map)
    {
        if (!map.containsKey("brandId") || StringUtils.isBlank(map.get("brandId").toString())
                || !map.containsKey("seriesName") || StringUtils.isBlank(map.get("seriesName").toString())
                || !map.containsKey("modelName") || StringUtils.isBlank(map.get("modelName").toString())
                || !map.containsKey("status") || StringUtils.isBlank(map.get("status").toString())
        ){
            return AjaxResult.error("缺少参数");
        }
        return toAjax(wcfMobileModelService.addWcfMobileModel(map));
    }

    /**
     * 修改手机型号
     */
    @PreAuthorize("@ss.hasPermi('wcf:WcfMobileModel:edit')")
    @Log(title = "手机型号", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult editWcfMobileModel(@RequestBody Map<String,Object> map)
    {
        if (!map.containsKey("brandId") || StringUtils.isBlank(map.get("brandId").toString())
                || !map.containsKey("seriesName") || StringUtils.isBlank(map.get("seriesName").toString())
                || !map.containsKey("modelId") || StringUtils.isBlank(map.get("modelId").toString())
                || !map.containsKey("modelName") || StringUtils.isBlank(map.get("modelName").toString())
                || !map.containsKey("status") || StringUtils.isBlank(map.get("status").toString())
        ){
            return AjaxResult.error("缺少参数");
        }
        return toAjax(wcfMobileModelService.editWcfMobileModel(map));
    }

    /**
     * 获取手机型号详细信息
     */
    @GetMapping("/getDetail")
    public AjaxResult getDetail(@RequestParam Map<String,Object> map)
    {
        if (!map.containsKey("modelId")){
            return AjaxResult.error("缺少参数");
        }
        Long modelId = MapUtils.getLong(map, "modelId");
        return AjaxResult.success(wcfMobileModelService.getDetail(modelId));
    }

    /**
     * 获取手机型号下拉列表
     * @param map
     * @return
     */
    @GetMapping("/getSelectList")
    public AjaxResult getSelectList(@RequestParam Map<String,Object> map){
        if (!map.containsKey("seriesId")){
            return AjaxResult.error("缺少参数");
        }

        return AjaxResult.success(wcfMobileModelService.getSelectList(map));
    }

}
